package com.fzshang.shopping.commen.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzshang.shopping.commen.bean.Classification;
import com.fzshang.shopping.commen.bean.CommodityClassification;
import com.fzshang.shopping.commen.bean.Good;
import com.fzshang.shopping.commen.bean.GoodImage;
import com.fzshang.shopping.commen.bean.layuiBean.ResultPage;
import com.fzshang.shopping.commen.bean.layuiBean.VoPage;
import com.fzshang.shopping.commen.mapper.GoodMapper;
import com.fzshang.shopping.commen.service.ClassificationService;
import com.fzshang.shopping.commen.service.CommodityClassificationService;
import com.fzshang.shopping.commen.service.GoodImageService;
import com.fzshang.shopping.commen.service.GoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.accessibility.AccessibleComponent;
import java.awt.geom.QuadCurve2D;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品 服务实现类
 * </p>
 *
 * @author 冯政尚
 * @since 2020-03-08
 */
@Service
public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements GoodService {



    @Autowired
    GoodImageService goodImageService;
    /**
     * @param voPage
     * @return 后台查询
     */
    @Override
    public ResultPage<Good> selectMyPage(VoPage voPage, Good good) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1) * voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("goodName", good.getGoodName());
        paramMap.put("commodityId", good.getCommodityId());
        paramMap.put("classificationId", good.getClassificationId());
        paramMap.put("freeShipping", good.getFreeShipping());
        paramMap.put("businesses", good.getBusinesses());
        List<Good> list = baseMapper.selectMyPage(paramMap);
        for (int i = 0; i < list.size(); i++) {
            Good good1 = list.get(i);
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("good_id",good1.getId());
            List<GoodImage> goodImages = goodImageService.list(queryWrapper);
            for (int j = 0; j < goodImages.size(); j++) {
                list.get(i).setGoodUrl(goodImages.get(0).getUrl());
            }

        }
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<Good> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    /**
     * @param voPage
     * @return 后台查询每日推荐
     */
    @Override
    public ResultPage<Good> selectMyPage1(VoPage voPage) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1) * voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        List<Good> list = baseMapper.selectMyPage1(paramMap);
        Integer count = baseMapper.countMyPage1(paramMap);
        ResultPage<Good> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }
    @Autowired
    CommodityClassificationService commodityClassificationService;
    @Autowired
    ClassificationService classificationService;

    /**
     * @param voPage
     * @return 后台查询今日好货
     */
    @Override
    public ResultPage<Good> selectMyPageQuality(VoPage voPage) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1) * voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        List<Good> list = baseMapper.selectState();
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getState()==1){
                list.get(i).setType(1);
            }else{
                list.get(i).setType(2);
            }
        }
        Integer count = list.size();
        ResultPage<Good> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }


}
